{{include file="header.html"}}
{{include file="menu.html"}}
{{assign var="sex" value='sex'|C}}
		<!-- 右边侧边栏 -->
		<div class="right">
			<!-- 个人信息部分 -->
			<div class="item">
				<form action="index.php" id="myform" method="post" class="ajaxSubmit" onsubmit="return false">
				<input type="hidden" name="id" value="{{$result.id}}"/>
				<div class="btn">
					<span class="span_t">{{if $result.team_name}}修改项目-->{{$result.team_name}}{{else}}添加项目{{/if}}</span>
					<button class="change">{{if $result}}修改{{else}}添加{{/if}}</button>
					<button class="sure" onclick="check();">确认</button>
					<a href="javascript：void:(0);" class="print" onclick="javascript:history.go(-1);">返回</a>
					<div class="clear"></div>
				</div>
				<table border="1" class="item_detail">
					<tr>
						<td style="width:80px;">项目名称<span class="need">*</span></td>
						<td colspan="6"><input type="text" value="{{if $result.params.item}}{{$result.params.item}}{{/if}}" name="params[item]"></td>
					</tr>
					<tr>
						<td style="width:80px;">团队名称<span class="need">*</span></td>
						<td colspan="6"><input type="text" value="{{if $result.params.team}}{{$result.params.team}}{{/if}}" name="params[team]"></td>
					</tr>
				</table>
				<!-- 选择团队成员 -->
				<table border="1" class="item_detail" style="border-top:none;" id="com">
					<tr>
						<td rowspan="10" style="width:80px;">队员(不超10人)
							<div class="home email add_com">
								<svg class="icon" aria-hidden="true">
									<use xlink:href="#icon-icon-test"></use>
								</svg>
							</div>
						</td>
						<td style="width:100px;">姓名</td>
						<td style="width:120px;">性别</td>
						<td style="width:120px;">手机</td>
						<td style="width:120px;">院系</td>
						<td style="width:190px;">班级</td>
					</tr>
					<tr class="no_company">
						<td colspan="5">无</td>
					</tr>
					{{if $result.params.company}}
					{{foreach from=$result.params.company item=val key=key}}
					<tr>
						<td>
							<input type="text" name="params[company][name_c][{{$key}}]" value="{{$val.name_c}}">
						</td>
						<td>
							<input type="text" name="params[company][sex_c][{{$key}}]" value="{{$val.sex_c}}">
						</td>
						<td>
							<input type="text" name="params[company][phone_c][{{$key}}]" value="{{$val.phone_c}}">
						</td>
						<td>
							<input type="text" name="params[company][xy_n][{{$key}}]" value="{{$val.xy_n}}">
						</td>
						<td>
							<input type="text" name="params[company][grade_n][{{$key}}]" value="{{$val.grade_n}}" style="width:130px;"><a href='javascript:;'style='display:none;' class='home email del' ><svg class='icon' style='color:red;' aria-hidden='true'><use xlink:href='#icon-guanbi'></use></svg></a>
						</td>
					</tr>
					{{/foreach}}
					{{/if}}
				</table>
				<!-- 选择老师 -->
				<table border="1" class="item_detail" style="border-top:none;" id="teacher">
					<tr>
						<td rowspan="10" style="width:80px;">指导老师(1人)
							<div class="home email add_teacher_to">
								<svg class="icon" aria-hidden="true">
									<use xlink:href="#icon-icon-test"></use>
								</svg>
							</div>
						</td>
						<td style="width:100px;">姓名</td>
						<td style="width:120px;">性别</td>
						<td style="width:120px;">院系</td>
						<td style="width:120px;">职称</td>
						<td style="width:190px;">研究方向</td>
					</tr>
					{{if !$result.params.teacher}}
					<tr class="no_teacher">
						<td colspan="5">无</td>
					</tr>
					{{else}}
					<tr class="teacher_list">
						<td>
							<input type="text" name="params[teacher][name_t]" value="{{$result.params.teacher.name_t}}">
						</td>
						<td>
							<input type="text" name="params[teacher][sex_te]" value="{{$result.params.teacher.sex_te}}">
						</td>
						<td>
							<input type="text" name="params[teacher][xy_name_t]" value="{{$result.params.teacher.xy_name_t}}">
						</td>
						<td>
							<input type="text" name="params[teacher][job_t]" value="{{$result.params.teacher.job_t}}">
						</td>
						<td>
							<input type="text" name="params[teacher][process_te]" value="{{$result.params.teacher.process_te}}">
						</td>
					</tr>
					{{/if}}
				</table>
				<!-- 公司简介 -->
				<table border="1" class="item_detail" style="border-top:none;">
					<tr>
						<td style="width:80px;">项目意义</td>
						<td>
							<textarea name="params[team_mean]" id="" cols="30" rows="10">{{if $result.params.team_mean}}{{$result.params.team_mean}}{{/if}}</textarea>
						</td>
					</tr>
					<tr>
						<td style="width:80px;">项目内容</td>
						<td>
							<textarea name="params[team_content]" id="" cols="30" rows="10">{{if $result.params.team_content}}{{$result.params.team_content}}{{/if}}</textarea>
						</td>
					</tr>
				</table>
				</form>
			</div>
		</div>
		<div class="clear"></div>
	</div>
	<!-- 添加合伙人窗口 -->
	<div class="transmit">
		<div class="main">
			<h4>添加合伙人</h4>
			<div class="cont_m" style="height:150px;">
				<form action="" id="add_c">
					<table border="1px">
						<tr>
							<td class="one">姓名<span class="need">*</span></td>
							<td class="two"><input type="text" name="name" value=""></td>
							<td class="one">手机号<span class="need">*</span></td>
							<td class="two"><input type="text" name="phone" value=""></td>
							<td class="one">性别<span class="need">*</span></td>
							<td class="two">
								<label for="manp"><input type="radio" name="sexp" id="manp" value="1">男</label>
								<label for="womanp"><input type="radio" checked="" name="sexp" id="womanp" value="2">女</label>
							</td>
						</tr>
						<tr>
							<td class="one">学院<span class="need">*</span></td>
							<td class="two"><input type="text" name="xy_name" value=""></td>
							<td class="one">班级<span class="need">*</span></td>
							<td class="two"><input type="text" name="grade" value=""></td>
							<td class="one"></td>
							<td class="two"></td>
						</tr>
						<tr>
							<td>操作</td>
							<td class="one" colspan="5" style="width:100%;">
								<input class="btn_add" disabled="false" value="添加">
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div class="home close_tran">
				<svg class="icon" aria-hidden="true">
					<use xlink:href="#icon-guanbi"></use>
				</svg>
			</div>
			<span class="tosay"></span>
		</div>
	</div>
	<!-- 选择老师窗口 -->
	<div class="transmit_t">
		<div class="main">
			<h4>选择老师</h4>
			<div class="cont_m te">
				<form action="" id="form_t">
					<table border="1px">
						<tr>
							<td style="width:50px;">选择</td>
							<td style="width:50px;">姓名</td>
							<td style="width:40px;">性别</td>
							<td style="width:90px;">手机号</td>
							<td style="width:120px;">职称</td>
							<td style="width:120px;">研究方向</td>
							<td style="width:100px;">所属院系</td>
							<td style="width:60px;">个人简介</td>
						</tr>
						{{if $result.teacher}}
						{{foreach from=$result.teacher item=val key=key}}
						<tr>
							<td><input type="radio" name="choose" value="{{$val.id}}"></td>
							<td><input type="text" name="name" value="{{$val.username}}"></td>
							<td><input type="text" name="sex" value="{{$sex[$val.sex]}}"></td>
							<td><input type="text" name="phone" value="{{$val.params.mobile}}"></td>
							<td><input type="text" name="job" value="{{$val.params.professional}}"></td>
							<td><input type="text" name="process" value="{{$val.params.direction}}"></td>
							<td><input type="text" name="xy_name" value="{{$val.params.faculty}}"></td>
							<td><a href="index.php?app=Work&act=teacher_info&id={{$val.id}}">更多</a></td>
						</tr>		
						{{/foreach}}
						{{/if}}	
					</table>
				</form>
			</div>
			<div class="btn">
				<button class="add add_t">确认</button>
			</div>
			<div class="home close_tran">
				<svg class="icon" aria-hidden="true">
					<use xlink:href="#icon-guanbi"></use>
				</svg>
			</div>
		</div>
	</div>
	<!-- 回到顶部 -->
	<div class="toTop"><span>↑</span>顶部</div>
	<script type="text/javascript">
	$(function(){
		$(".right input,.right textarea").attr("disabled","true").css("border","none");
		$("#form_t input[type='text']").attr("disabled","true").css("border","none");
		$(".add_com,.add_teacher_to").hide();

		// 点击添加相应的窗口进行显示与影藏
		$(".add_com").click(function(){
			$(".btn_add").attr('disabled','false').removeClass("can");
			if($("#com tr").length >= '10')
				ui.error('合伙人至多只能有10个！');
			else{
				$(".transmit").show();
				$(".transmit_t").hide();
			}
		})

		$(".add_teacher_to").click(function(){
			$(".transmit_t").show();
			$(".transmit").hide();
		})

		// 判断合伙人是否需要显示“无”这一行
		if($("#com input").length>0){
			$(".no_company").hide();
		}
		// 判断选择老师是否需要显示“无”这一行
		if($("#teacher input").length>0){
			$(".no_teacher").hide();
		}

		// 使输入框可用
		function inputAbled(){
			$(".item input,textarea").removeAttr("disabled").css("border","1px solid #D8D8D8");
			// $("#teacher input").attr("disabled","false").css("border","none");
			$("#teacher input").attr("readonly",true).css("border","none");
		}

		// 点击修改按钮时改变样式
		$(".change").click(function(){
			inputAbled();
			$(this).hide();
			$(".sure,.del,.add_com,.add_teacher_to").show();
		})

		// 添加合伙人行函数
 		function add_company(name,input_n,sex_t,sex_n,phone,phone_n,xy_n,xy_v,grade_n,grade_v){
			var tr = "<tr><td><input value="+name+" name='"+input_n+"'></td><td><input type='text' name='"+sex_n+"' value='"+sex_t+"'/></td><td><input value='"+phone+"' name='"+phone_n+"'></td><td><input type='text' name='"+xy_n+"' value="+xy_v+"/></td><td><input type='text' name='"+grade_n+"' value="+grade_v+" style='width:130px;'/><a href='javascript:;'style='display:none;' class='home email del'><svg class='icon' style='color:red;' aria-hidden='true'><use xlink:href='#icon-guanbi'></use></svg></a></td></tr>";
			return tr;
		}

   		// 添加合伙人
		$(".btn_add").click(function(){
			// 提取表单值
			var d = {};
		    var t = $("#add_c").serializeArray();
		    $.each(t, function() {
		      d[this.name] = this.value;
		    });
		    var name = JSON.stringify(d.name);  //输入的姓名
		    var phone = parseInt(JSON.stringify(d.phone).substring(1));//输入的电话
		    var sex = parseInt(JSON.stringify(d.sexp).substring(1));//选中性别值
		    var xy_v = JSON.stringify(d.xy_name);//输入的学院名
		    var grade_v = JSON.stringify(d.grade);//输入的年级名
		    var process_v = JSON.stringify(d.process);//输入的专业名
		    if(sex==1){
		    	sex="男";
		    }else{
		    	sex="女";
		    }

		    // 添加合伙人
		    $("#com").append(add_company(name,"params[company][name_c][]",sex,"params[company][sex_c][]",phone,"params[company][phone_c][]","params[company][xy_n][]",xy_v,"params[company][grade_n][]",grade_v));

		    // 清除表单
			$("#add_c input[type='text']").val("");

			// 点击删除号删除相应的行
		    $(".del").click(function(){
				$(this).parent().parent("tr").remove();
				if($(".del").length<1){
					$(".no_company").show();
				}
			})
		   
		    // 添加合伙人后影藏弹框并且隐藏“无”一行
		    $(".transmit").hide();
		    if($("#com").find(".no_company").length==1){
		    	$(".no_company").hide();
		    }
		    inputAbled();
		    //使页面仍然处于编辑状态
		    $(".item input,textarea").removeAttr("disabled").css("border","1px solid #D8D8D8");
			$("#teacher input").attr("readonly",true).css("border","none");
			$(".sure,.del").show();
		})

		// 点击行选中老师
		$(".te tr td").click(function(){
			$(this).parent().find("input[type='radio']").attr("checked",true);
		})

		// 点击删除号删除相应的行
	    $(".del").click(function(){
			$(this).parent().parent("tr").remove();
			if($(".del").length<1){
				$(".no_company").show();
			}
		})

		// 添加老师
		function add_teacher(name,name_t,sex_t,sex_te,xy_name,xy_name_t,job,job_t,process,process_te,id,id_t){
			var tr = "<tr class=teacher_list><input type='hidden' name='"+id_t+"' value="+id+"><td><input name='"+name_t+"' value="+name+"></td><td><input type='text' name='"+sex_te+"' value='"+sex_t+"'/></td><td><input name='"+xy_name_t+"' value='"+xy_name+"'></td><td><input type='text' name='"+job_t+"' value='"+job+"' /></td><td><input type='process' name='"+process_te+"' value='"+process+"'/></td></tr>";
			return tr;
		}

		// 点击添加老师进行验证信息
		$(".transmit_t input").blur(function(){
			if($("input[name='teacher_name']").val()==""){
				showNotice("用户名不能为空");
				return false;
			}
			$(".add_t").addClass("can");
			$(".add_t").removeAttr("disabled");
		})	
		
		// 选择老师弹窗中通过选中的多选框的值获得相对应name的input值
		function check_c(name){
			return $("#form_t input[name='choose'][value='"+obj[k].value+"']").parent().parent().find("input[name='"+name+"']").val();
		}

		// 将所有选中老师的信息存入数组
		function teacher(){
		    obj = document.getElementsByName("choose");
		    check_val = [];
		    check_name = [];
		    check_sex = [];
		    check_phone = [];
		    check_job = [];
		    check_process= [];
		    check_xy_name = [];
		    check_id = [];
		    var num=0;
		    for(k in obj){
		        if(obj[k].checked){ 
		        	num++;
		            check_val.push(obj[k].value);
		        	check_name.push(check_c("name"));
		        	check_sex.push(check_c("sex"));
		        	check_phone.push(check_c("phone"));
		        	check_job.push(check_c("job"));
		        	check_process.push(check_c("process"));
		        	check_xy_name.push(check_c("xy_name"));
		        	check_id.push(check_c("choose"));
		        	if(num>1){
		        		alert("最多只能选1个指导老师");
		        		num=1;
		        	}
		        }
		    }
		    var content = [];
		    content.push(add_teacher(check_name,"params[teacher][name_t]",check_sex,"params[teacher][sex_te]",check_xy_name,"params[teacher][xy_name_t]",check_job,"params[teacher][job_t]",check_process,"params[teacher][process_te]",check_id,"teacher_id"));
		    $(".teacher_list").remove();
		    $("#teacher").append(content);
		}

		$(".add_t").click(function(){
			$(".no_teacher").nextAll().remove();
			teacher();
			$(".transmit_t").hide();
			if($("#teacher input").length>0){
				$(".no_teacher").hide();
			}
			inputAbled();
			// 点击修改按钮时改变样式
			$(".item input,textarea").removeAttr("disabled").css("border","1px solid #D8D8D8");
			$("#teacher input").attr("readonly",true).css("border","none");

		})

		// 日期调用
		laydate.render({
		  elem: '#datepicker' //指定元素
		});
		// 日期调用
		laydate.render({
		  elem: '#datepicker1' //指定元素
		}); 
	})

	$("#myform input").keydown(function(e){
		var curkey = e.which; 
		if(curkey == 13){ 
			check();
		}
	}); 

	//信息验证
	function check(){
	    var params = $("#myform").serialize();
	    $.post('{{"index.php?app=Project&act=info"|URL}}',params,function(result){
	        if(result.statusCode=='200'){
	        	ui.success(result.message);
	        	document.cookie="time="+Date.parse(new Date());
	   			// 点击确认按钮时改变样式
				$(".right input,.right textarea").attr("disabled","false").css("border","none");
				$(".sure").hide();
				$(".change").show();
				var url = "{{$smarty.const.__PROJECT__}}Project/student"; 
				document.location.href = url;
	        }else if(result.statusCode=='300'){
	        	ui.error(result.message);
	        }
	    },'json');
	};

	// 点击添加合伙人进行验证信息
	$(".transmit input").blur(function(){
		var com_params = $("#add_c").serialize();
    	$.post('{{"index.php?app=Work&act=com_proving"|URL}}',com_params,function(result){
	        if(result.statusCode=='200'){
	   			$(".tosay").html("");
	   			$(".btn_add").addClass("can");
				$(".btn_add").removeAttr("disabled");
				$(".change").hide();
	        }else if(result.statusCode=='300'){
	        	$(".tosay").html(result.message);
	        }
	    },'json');
	})	
	</script>
</body>
</html>